package com.lishangshan.oas_system.model.dao.system;

import com.lishangshan.oas_system.model.entity.system.SystemMenu;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;


public interface SystemMenuDao extends PagingAndSortingRepository<SystemMenu, Long> {
    // 父菜单 分页
    @Query("from SystemMenu as menu where menu.parentId = ?1 order by menu.sortId")
    Page<SystemMenu> findAllByFu(@Param("parentId") Long parentId, Pageable pa);

    // like 根据 菜单 名称 模糊 查询
    @Query("select menu from SystemMenu as menu where menu.menuName like %?1%")
    Page<SystemMenu> findByMuneName(String val, Pageable pa);

  /*  // 子菜单 分页
    @Query("from SystemMenu as menu where menu.parentId <> ?1 and menu.parentId is not null and menu.parentId <> 999")
    Page<SystemMenu> findAllByZi(long l, Pageable pa);*/

    // 子菜单 分页
    @Query("from SystemMenu as menu where menu.parentId = ?1 order by menu.sortId")
    Page<SystemMenu> findAllByZi(long l, Pageable pa);

    @Query("update SystemMenu as menu set menu.sortId=?2 where menu.menuId =?1")
    @Transactional
    @Modifying
    void upmenu(Long id, int sortId);
}
